//===----------------------------------------------------------------------===//
//
// This source file is part of the Soto for AWS open source project
//
// Copyright (c) 2017-2024 the Soto project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Soto project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// THIS FILE IS AUTOMATICALLY GENERATED by https://github.com/soto-project/soto-codegenerator.
// DO NOT EDIT.

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif
@_exported import SotoCore

/// Service object for interacting with AWS BackupSearch service.
///
/// Backup Search Backup Search is the recovery point and item level search for Backup. For additional information, see:    Backup API Reference     Backup Developer Guide
public struct BackupSearch: AWSService {
    // MARK: Member variables

    /// Client used for communication with AWS
    public let client: AWSClient
    /// Service configuration
    public let config: AWSServiceConfig

    // MARK: Initialization

    /// Initialize the BackupSearch client
    /// - parameters:
    ///     - client: AWSClient used to process requests
    ///     - region: Region of server you want to communicate with. This will override the partition parameter.
    ///     - partition: AWS partition where service resides, standard (.aws), china (.awscn), government (.awsusgov).
    ///     - endpoint: Custom endpoint URL to use instead of standard AWS servers
    ///     - middleware: Middleware chain used to edit requests before they are sent and responses before they are decoded 
    ///     - timeout: Timeout value for HTTP requests
    ///     - byteBufferAllocator: Allocator for ByteBuffers
    ///     - options: Service options
    public init(
        client: AWSClient,
        region: SotoCore.Region? = nil,
        partition: AWSPartition = .aws,
        endpoint: String? = nil,
        middleware: AWSMiddlewareProtocol? = nil,
        timeout: TimeAmount? = nil,
        byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator(),
        options: AWSServiceConfig.Options = []
    ) {
        self.client = client
        self.config = AWSServiceConfig(
            region: region,
            partition: region?.partition ?? partition,
            serviceName: "BackupSearch",
            serviceIdentifier: "backup-search",
            serviceProtocol: .restjson,
            apiVersion: "2018-05-10",
            endpoint: endpoint,
            errorType: BackupSearchErrorType.self,
            middleware: middleware,
            timeout: timeout,
            byteBufferAllocator: byteBufferAllocator,
            options: options
        )
    }





    // MARK: API Calls

    /// This operation retrieves metadata of a search job, including its progress.
    @Sendable
    @inlinable
    public func getSearchJob(_ input: GetSearchJobInput, logger: Logger = AWSClient.loggingDisabled) async throws -> GetSearchJobOutput {
        try await self.client.execute(
            operation: "GetSearchJob", 
            path: "/search-jobs/{SearchJobIdentifier}", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// This operation retrieves metadata of a search job, including its progress.
    ///
    /// Parameters:
    ///   - searchJobIdentifier: Required unique string that specifies the search job.
    ///   - logger: Logger use during operation
    @inlinable
    public func getSearchJob(
        searchJobIdentifier: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> GetSearchJobOutput {
        let input = GetSearchJobInput(
            searchJobIdentifier: searchJobIdentifier
        )
        return try await self.getSearchJob(input, logger: logger)
    }

    /// This operation retrieves the metadata of an export job. An export job is an operation that transmits the results of a search job to a specified S3 bucket in a .csv file. An export job allows you to retain results of a search beyond the search job's scheduled retention of 7 days.
    @Sendable
    @inlinable
    public func getSearchResultExportJob(_ input: GetSearchResultExportJobInput, logger: Logger = AWSClient.loggingDisabled) async throws -> GetSearchResultExportJobOutput {
        try await self.client.execute(
            operation: "GetSearchResultExportJob", 
            path: "/export-search-jobs/{ExportJobIdentifier}", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// This operation retrieves the metadata of an export job. An export job is an operation that transmits the results of a search job to a specified S3 bucket in a .csv file. An export job allows you to retain results of a search beyond the search job's scheduled retention of 7 days.
    ///
    /// Parameters:
    ///   - exportJobIdentifier: This is the unique string that identifies a specific export job. Required for this operation.
    ///   - logger: Logger use during operation
    @inlinable
    public func getSearchResultExportJob(
        exportJobIdentifier: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> GetSearchResultExportJobOutput {
        let input = GetSearchResultExportJobInput(
            exportJobIdentifier: exportJobIdentifier
        )
        return try await self.getSearchResultExportJob(input, logger: logger)
    }

    /// This operation returns a list of all backups (recovery points) in a paginated format that were included in the search job. If a search does not display an expected backup in the results, you can call this operation to display each backup included in the search. Any backups that were not included because they have a FAILED status from a permissions issue will be displayed, along with a status message. Only recovery points with a backup index that has a status of ACTIVE will be included in search results. If the index has any other status, its status will be displayed along with a status message.
    @Sendable
    @inlinable
    public func listSearchJobBackups(_ input: ListSearchJobBackupsInput, logger: Logger = AWSClient.loggingDisabled) async throws -> ListSearchJobBackupsOutput {
        try await self.client.execute(
            operation: "ListSearchJobBackups", 
            path: "/search-jobs/{SearchJobIdentifier}/backups", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// This operation returns a list of all backups (recovery points) in a paginated format that were included in the search job. If a search does not display an expected backup in the results, you can call this operation to display each backup included in the search. Any backups that were not included because they have a FAILED status from a permissions issue will be displayed, along with a status message. Only recovery points with a backup index that has a status of ACTIVE will be included in search results. If the index has any other status, its status will be displayed along with a status message.
    ///
    /// Parameters:
    ///   - maxResults: The maximum number of resource list items to be returned.
    ///   - nextToken: The next item following a partial list of returned backups included in a search job. For example, if a request is made to return MaxResults number of backups, NextToken allows you to return more items in your list starting at the location pointed to by the next token.
    ///   - searchJobIdentifier: The unique string that specifies the search job.
    ///   - logger: Logger use during operation
    @inlinable
    public func listSearchJobBackups(
        maxResults: Int? = nil,
        nextToken: String? = nil,
        searchJobIdentifier: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> ListSearchJobBackupsOutput {
        let input = ListSearchJobBackupsInput(
            maxResults: maxResults, 
            nextToken: nextToken, 
            searchJobIdentifier: searchJobIdentifier
        )
        return try await self.listSearchJobBackups(input, logger: logger)
    }

    /// This operation returns a list of a specified search job.
    @Sendable
    @inlinable
    public func listSearchJobResults(_ input: ListSearchJobResultsInput, logger: Logger = AWSClient.loggingDisabled) async throws -> ListSearchJobResultsOutput {
        try await self.client.execute(
            operation: "ListSearchJobResults", 
            path: "/search-jobs/{SearchJobIdentifier}/search-results", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// This operation returns a list of a specified search job.
    ///
    /// Parameters:
    ///   - maxResults: The maximum number of resource list items to be returned.
    ///   - nextToken: The next item following a partial list of returned search job results. For example, if a request is made to return MaxResults number of search job results, NextToken allows you to return more items in your list starting at the location pointed to by the next token.
    ///   - searchJobIdentifier: The unique string that specifies the search job.
    ///   - logger: Logger use during operation
    @inlinable
    public func listSearchJobResults(
        maxResults: Int? = nil,
        nextToken: String? = nil,
        searchJobIdentifier: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> ListSearchJobResultsOutput {
        let input = ListSearchJobResultsInput(
            maxResults: maxResults, 
            nextToken: nextToken, 
            searchJobIdentifier: searchJobIdentifier
        )
        return try await self.listSearchJobResults(input, logger: logger)
    }

    /// This operation returns a list of search jobs belonging to an account.
    @Sendable
    @inlinable
    public func listSearchJobs(_ input: ListSearchJobsInput, logger: Logger = AWSClient.loggingDisabled) async throws -> ListSearchJobsOutput {
        try await self.client.execute(
            operation: "ListSearchJobs", 
            path: "/search-jobs", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// This operation returns a list of search jobs belonging to an account.
    ///
    /// Parameters:
    ///   - byStatus: Include this parameter to filter list by search job status.
    ///   - maxResults: The maximum number of resource list items to be returned.
    ///   - nextToken: The next item following a partial list of returned search jobs. For example, if a request is made to return MaxResults number of backups, NextToken allows you to return more items in your list starting at the location pointed to by the next token.
    ///   - logger: Logger use during operation
    @inlinable
    public func listSearchJobs(
        byStatus: SearchJobState? = nil,
        maxResults: Int? = nil,
        nextToken: String? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> ListSearchJobsOutput {
        let input = ListSearchJobsInput(
            byStatus: byStatus, 
            maxResults: maxResults, 
            nextToken: nextToken
        )
        return try await self.listSearchJobs(input, logger: logger)
    }

    /// This operation exports search results of a search job to a specified destination S3 bucket.
    @Sendable
    @inlinable
    public func listSearchResultExportJobs(_ input: ListSearchResultExportJobsInput, logger: Logger = AWSClient.loggingDisabled) async throws -> ListSearchResultExportJobsOutput {
        try await self.client.execute(
            operation: "ListSearchResultExportJobs", 
            path: "/export-search-jobs", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// This operation exports search results of a search job to a specified destination S3 bucket.
    ///
    /// Parameters:
    ///   - maxResults: The maximum number of resource list items to be returned.
    ///   - nextToken: The next item following a partial list of returned backups included in a search job. For example, if a request is made to return MaxResults number of backups, NextToken allows you to return more items in your list starting at the location pointed to by the next token.
    ///   - searchJobIdentifier: The unique string that specifies the search job.
    ///   - status: The search jobs to be included in the export job can be filtered by including this parameter.
    ///   - logger: Logger use during operation
    @inlinable
    public func listSearchResultExportJobs(
        maxResults: Int? = nil,
        nextToken: String? = nil,
        searchJobIdentifier: String? = nil,
        status: ExportJobStatus? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> ListSearchResultExportJobsOutput {
        let input = ListSearchResultExportJobsInput(
            maxResults: maxResults, 
            nextToken: nextToken, 
            searchJobIdentifier: searchJobIdentifier, 
            status: status
        )
        return try await self.listSearchResultExportJobs(input, logger: logger)
    }

    /// This operation returns the tags for a resource type.
    @Sendable
    @inlinable
    public func listTagsForResource(_ input: ListTagsForResourceRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> ListTagsForResourceResponse {
        try await self.client.execute(
            operation: "ListTagsForResource", 
            path: "/tags/{ResourceArn}", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// This operation returns the tags for a resource type.
    ///
    /// Parameters:
    ///   - resourceArn: The Amazon Resource Name (ARN) that uniquely identifies the resource.&gt;
    ///   - logger: Logger use during operation
    @inlinable
    public func listTagsForResource(
        resourceArn: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> ListTagsForResourceResponse {
        let input = ListTagsForResourceRequest(
            resourceArn: resourceArn
        )
        return try await self.listTagsForResource(input, logger: logger)
    }

    /// This operation creates a search job which returns recovery points filtered by SearchScope and items filtered by ItemFilters. You can optionally include ClientToken, EncryptionKeyArn, Name, and/or Tags.
    @Sendable
    @inlinable
    public func startSearchJob(_ input: StartSearchJobInput, logger: Logger = AWSClient.loggingDisabled) async throws -> StartSearchJobOutput {
        try await self.client.execute(
            operation: "StartSearchJob", 
            path: "/search-jobs", 
            httpMethod: .PUT, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// This operation creates a search job which returns recovery points filtered by SearchScope and items filtered by ItemFilters. You can optionally include ClientToken, EncryptionKeyArn, Name, and/or Tags.
    ///
    /// Parameters:
    ///   - clientToken: Include this parameter to allow multiple identical calls for idempotency. A client token is valid for 8 hours after the first request that uses it is completed. After this time, any request with the same token is treated as a new request.
    ///   - encryptionKeyArn: The encryption key for the specified search job.
    ///   - itemFilters: Item Filters represent all input item properties specified when the search was created. Contains either EBSItemFilters or S3ItemFilters
    ///   - name: Include alphanumeric characters to create a name for this search job.
    ///   - searchScope: This object can contain BackupResourceTypes, BackupResourceArns, BackupResourceCreationTime, BackupResourceTags, and SourceResourceArns to filter the recovery points returned by the search job.
    ///   - tags: List of tags returned by the operation.
    ///   - logger: Logger use during operation
    @inlinable
    public func startSearchJob(
        clientToken: String? = nil,
        encryptionKeyArn: String? = nil,
        itemFilters: ItemFilters? = nil,
        name: String? = nil,
        searchScope: SearchScope,
        tags: [String: String]? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> StartSearchJobOutput {
        let input = StartSearchJobInput(
            clientToken: clientToken, 
            encryptionKeyArn: encryptionKeyArn, 
            itemFilters: itemFilters, 
            name: name, 
            searchScope: searchScope, 
            tags: tags
        )
        return try await self.startSearchJob(input, logger: logger)
    }

    /// This operations starts a job to export the results of search job to a designated S3 bucket.
    @Sendable
    @inlinable
    public func startSearchResultExportJob(_ input: StartSearchResultExportJobInput, logger: Logger = AWSClient.loggingDisabled) async throws -> StartSearchResultExportJobOutput {
        try await self.client.execute(
            operation: "StartSearchResultExportJob", 
            path: "/export-search-jobs", 
            httpMethod: .PUT, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// This operations starts a job to export the results of search job to a designated S3 bucket.
    ///
    /// Parameters:
    ///   - clientToken: Include this parameter to allow multiple identical calls for idempotency. A client token is valid for 8 hours after the first request that uses it is completed. After this time, any request with the same token is treated as a new request.
    ///   - exportSpecification: This specification contains a required string of the destination bucket; optionally, you can include the destination prefix.
    ///   - roleArn: This parameter specifies the role ARN used to start the search results export jobs.
    ///   - searchJobIdentifier: The unique string that specifies the search job.
    ///   - tags: Optional tags to include. A tag is a key-value pair you can use to manage, filter, and search for your resources. Allowed characters include UTF-8 letters, numbers, spaces, and the following characters: + - = . _ : /.
    ///   - logger: Logger use during operation
    @inlinable
    public func startSearchResultExportJob(
        clientToken: String? = nil,
        exportSpecification: ExportSpecification,
        roleArn: String? = nil,
        searchJobIdentifier: String,
        tags: [String: String]? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> StartSearchResultExportJobOutput {
        let input = StartSearchResultExportJobInput(
            clientToken: clientToken, 
            exportSpecification: exportSpecification, 
            roleArn: roleArn, 
            searchJobIdentifier: searchJobIdentifier, 
            tags: tags
        )
        return try await self.startSearchResultExportJob(input, logger: logger)
    }

    /// This operations ends a search job. Only a search job with a status of RUNNING can be stopped.
    @Sendable
    @inlinable
    public func stopSearchJob(_ input: StopSearchJobInput, logger: Logger = AWSClient.loggingDisabled) async throws -> StopSearchJobOutput {
        try await self.client.execute(
            operation: "StopSearchJob", 
            path: "/search-jobs/{SearchJobIdentifier}/actions/cancel", 
            httpMethod: .PUT, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// This operations ends a search job. Only a search job with a status of RUNNING can be stopped.
    ///
    /// Parameters:
    ///   - searchJobIdentifier: The unique string that specifies the search job.
    ///   - logger: Logger use during operation
    @inlinable
    public func stopSearchJob(
        searchJobIdentifier: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> StopSearchJobOutput {
        let input = StopSearchJobInput(
            searchJobIdentifier: searchJobIdentifier
        )
        return try await self.stopSearchJob(input, logger: logger)
    }

    /// This operation puts tags on the resource you indicate.
    @Sendable
    @inlinable
    public func tagResource(_ input: TagResourceRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> TagResourceResponse {
        try await self.client.execute(
            operation: "TagResource", 
            path: "/tags/{ResourceArn}", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// This operation puts tags on the resource you indicate.
    ///
    /// Parameters:
    ///   - resourceArn: The Amazon Resource Name (ARN) that uniquely identifies the resource. This is the resource that will have the indicated tags.
    ///   - tags: Required tags to include. A tag is a key-value pair you can use to manage, filter, and search for your resources. Allowed characters include UTF-8 letters, numbers, spaces, and the following characters: + - = . _ : /.
    ///   - logger: Logger use during operation
    @inlinable
    public func tagResource(
        resourceArn: String,
        tags: [String: String],
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> TagResourceResponse {
        let input = TagResourceRequest(
            resourceArn: resourceArn, 
            tags: tags
        )
        return try await self.tagResource(input, logger: logger)
    }

    /// This operation removes tags from the specified resource.
    @Sendable
    @inlinable
    public func untagResource(_ input: UntagResourceRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> UntagResourceResponse {
        try await self.client.execute(
            operation: "UntagResource", 
            path: "/tags/{ResourceArn}", 
            httpMethod: .DELETE, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// This operation removes tags from the specified resource.
    ///
    /// Parameters:
    ///   - resourceArn: The Amazon Resource Name (ARN) that uniquely identifies the resource where you want to remove tags.
    ///   - tagKeys: This required parameter contains the tag keys you want to remove from the source.
    ///   - logger: Logger use during operation
    @inlinable
    public func untagResource(
        resourceArn: String,
        tagKeys: [String],
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> UntagResourceResponse {
        let input = UntagResourceRequest(
            resourceArn: resourceArn, 
            tagKeys: tagKeys
        )
        return try await self.untagResource(input, logger: logger)
    }
}

extension BackupSearch {
    /// Initializer required by `AWSService.with(middlewares:timeout:byteBufferAllocator:options)`. You are not able to use this initializer directly as there are not public
    /// initializers for `AWSServiceConfig.Patch`. Please use `AWSService.with(middlewares:timeout:byteBufferAllocator:options)` instead.
    public init(from: BackupSearch, patch: AWSServiceConfig.Patch) {
        self.client = from.client
        self.config = from.config.with(patch: patch)
    }
}

// MARK: Paginators

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension BackupSearch {
    /// Return PaginatorSequence for operation ``listSearchJobBackups(_:logger:)``.
    ///
    /// - Parameters:
    ///   - input: Input for operation
    ///   - logger: Logger used for logging
    @inlinable
    public func listSearchJobBackupsPaginator(
        _ input: ListSearchJobBackupsInput,
        logger: Logger = AWSClient.loggingDisabled
    ) -> AWSClient.PaginatorSequence<ListSearchJobBackupsInput, ListSearchJobBackupsOutput> {
        return .init(
            input: input,
            command: self.listSearchJobBackups,
            inputKey: \ListSearchJobBackupsInput.nextToken,
            outputKey: \ListSearchJobBackupsOutput.nextToken,
            logger: logger
        )
    }
    /// Return PaginatorSequence for operation ``listSearchJobBackups(_:logger:)``.
    ///
    /// - Parameters:
    ///   - maxResults: The maximum number of resource list items to be returned.
    ///   - searchJobIdentifier: The unique string that specifies the search job.
    ///   - logger: Logger used for logging
    @inlinable
    public func listSearchJobBackupsPaginator(
        maxResults: Int? = nil,
        searchJobIdentifier: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) -> AWSClient.PaginatorSequence<ListSearchJobBackupsInput, ListSearchJobBackupsOutput> {
        let input = ListSearchJobBackupsInput(
            maxResults: maxResults, 
            searchJobIdentifier: searchJobIdentifier
        )
        return self.listSearchJobBackupsPaginator(input, logger: logger)
    }
}

extension BackupSearch.ListSearchJobBackupsInput: AWSPaginateToken {
    @inlinable
    public func usingPaginationToken(_ token: String) -> BackupSearch.ListSearchJobBackupsInput {
        return .init(
            maxResults: self.maxResults,
            nextToken: token,
            searchJobIdentifier: self.searchJobIdentifier
        )
    }
}
